package gspushmq.v1.subscribe.core;

import org.java_websocket.WebSocket;

import gspushmq.model.Message;
import gspushmq.util.ToolsUtil;

public abstract class HandlerSubscribe implements Comparable<Object>, Runnable {

	private Message message;
	
	private WebSocket webSocket;
	
	private Integer priority = 0;

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public HandlerSubscribe() {}

	@Override
	public int compareTo(Object o) {
		Integer op = ToolsUtil.commonTo(o);
		
		return op.compareTo(this.getPriority());
	}
	
	public HandlerSubscribe(Message mess, WebSocket wst) {
		this.message = mess;
		this.webSocket = wst;
	}

	@Override
	public void run() {
		boolean valid = valid();
		if(valid){
			doHandler();
		}
	}

	public abstract void doHandler();
	
	public abstract boolean valid();
	
	public Message getMessage() {
		return message;
	}

	public WebSocket getWebSocket() {
		return webSocket;
	}
}
